package dao

import (
	"CDSystem/v2/model"
	"context"

	"go.mongodb.org/mongo-driver/bson"
)

func SaveProd(pi model.ProdInfo) (err error) {
	_, err = LabelColl.InsertOne(context.TODO(), pi)
	return
}

func GetLabelAndImage(image string) (label, image_data string, err error) {
	filter := bson.M{"image": image}
	res := LabelColl.FindOne(context.TODO(), filter)
	if res.Err() != nil {
		err = res.Err()
		return
	}
	pi := model.ProdInfo{}
	if err = res.Decode(&pi); err != nil {
		return
	}
	label, image_data = pi.Label, pi.ImageData
	return
}
